<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/all.conf.php');
require_once(__PHY_LIB."/inc/admin.api.inc.php");

$sFileBin = file_get_contents("php://input");
if (4 < strlen($sFileBin)) {
	$sFold1 = date('Y');
	$sFold2 = date('md');
	$sFile1 = date('His');
	$sFile2 = rand(100, 999);
	$sUrl = "/cms/{$sFold1}/{$sFold2}/{$sFile1}_{$sFile2}.png";
	mkdir_plus(dirname(__PHY_STO.$sUrl));
	file_put_contents(__PHY_STO.$sUrl, $sFileBin);
	die('{"err":"","msg":"'.__HST_STO.$sUrl.'"}');
}
elseif (0 === $_FILES['filedata']['error']) {
	$sFold1 = date('Y');
	$sFold2 = date('md');
	$sFile1 = date('His');
	$sFile2 = rand(100, 999);
	$sUrl = "/cms/{$sFold1}/{$sFold2}/{$sFile1}_{$sFile2}.png";
	mkdir_plus(dirname(__PHY_STO.$sUrl));
	if (move_uploaded_file($_FILES['filedata']['tmp_name'], __PHY_STO.$sUrl)) {
		die('{"err":"","msg":"'.__HST_STO.$sUrl.'"}');
	}
	else {
		die('{"err":"上传失败","msg":""}');
	}
}
else {
	die('{"err":"无文件上传","msg":""}');
}
?>
